#pragma once

class CBook
{
    uint games_total;
    uint games_count;
    uint parser_state;
    uint welo, belo, plycount, wwin, bwin, draw;
    uint min_rating;
    uint max_ply;
    char game[65536];
    uint _RstParser( );
    uint _ParseLine( char * line );
    uint _ParseValue( char * line, char * value );
    uint _IsTag( char * line );
    uint _HouseKeepingLine( char * line );
    uint _ParseMoves( char * line );
    uint _ExtractAndCollectMoves( char * line, char * game );

    T_NODE * base;
    uint base_size;

    uint _AddNodeToBook( T_NODE new_node );
    uint _SearchNodeInBook( T_NODE new_node );
    uint _FreeBase();

public:
    CBook();
    ~CBook();

    uint Create( char inputfile[1024], char outputfile[1024], uint min_elo, uint ply_limit );
    uint Load  ( char bookfile[1024] );

    uint GetMove( CBoard * board );
};

